local shengtang = fk.CreateSkill {
  name = "lingling__shengtang",
}
local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["lingling__shengtang"] = "升堂",
  [":lingling__shengtang"] = "出牌阶段限一次，你可以将一名手牌对你均不可见的其他角色的随机一张手牌与牌堆和弃牌堆中随机各一张牌混合，然后你猜测哪张牌来自其手牌，若：猜对，你对其造成1点伤害且其成为【桃】的目标时取消之直到其的回合结束；猜错，你失去1点体力并获得其中不为手牌的牌。",

  ["#lingling__shengtang-prompt"] = "升堂:将一名其他角色的一张手牌与牌堆顶，弃牌堆各一张牌混合后，猜测哪张来自其手牌",
  ["#lingling__shengtang-card"] = "升堂:选择你认为来自其手牌的一张牌",
  ["@@lingling__shengtang_not-turn"]="被升堂",

  ["@@lingling__shengtang_tonot"]="被升堂",
  ["#lingling__shengtang_good"]="今天谁也救不了你！来人！狗头铡伺候！",
  ["#lingling__shengtang_bad"]="此事颇有蹊跷！待本府再细细定夺。",
}
shengtang:addEffect("active",{
    name = "lingling__shengtang",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#lingling__shengtang-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(shengtang.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self,player, to_select, selected)
    if #selected == 0 and to_select ~= player then
    local target = to_select
    if target and not target:isKongcheng() then
    for _, cid in ipairs(target:getCardIds('h')) do
      if player:cardVisible(cid) then
        return false end
      end
      return true
    end
  end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards ={}
    if #room.draw_pile>0 then
      table.insert(cards,table.random(room.draw_pile,1)[1])
    end
    local cardIds = {}
    if #room.discard_pile>0 then
      table.insert(cards,table.random(room.discard_pile,1)[1])
    end
    local id = table.random(target.player_cards[Player.Hand])
    table.insert(cards, id)
    table.shuffle(cards)
    player:showCards(cards)
    room:delay(500)
    local id2 = room:askToChooseCard(player, {
      target = target,
      flag = { card_data = {
        { shengtang.name, cards }
      } },
      skill_name = shengtang.name,
      prompt = "#lingling__shengtang-card"
    })
    if id2 ~= id then
      room:sendLog{
        type = "#lingling__shengtang_bad",
        toast = true,
      }
      room:loseHp(player,1,shengtang.name)
      table.removeOne(cards,id)
      if #cards>0 and player:isAlive() then
      room:moveCardTo(cards, Player.Hand, player, fk.ReasonPrey, shengtang.name, nil, false, player.id)
      end
    else
      room:doIndicate(player.id,{target.id})
      room:sendLog{
        type = "#lingling__shengtang_good",
        toast = true,
      }
      room:setPlayerMark(target,"@@lingling__shengtang_tonot",1)
      room:damage{
        from = player,
        to = target,
        damage = 1,
        skillName = shengtang.name,
        damageType = fk.NormalDamage
      }
    end
  end,
})
shengtang:addEffect(fk.TurnEnd,{
  can_refresh = function (self, event, target, player, data)
    if target == player and player:getMark("@@lingling__shengtang_tonot")~=0 then
    return true 
  end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target,"@@lingling__shengtang_tonot",0)
  end,
})
shengtang:addEffect(fk.TargetConfirming,{
  can_refresh = function (self, event, target, player, data)
    if target == player and player:getMark("@@lingling__shengtang_tonot")~=0 then
      return data.card.name == "peach"
  end
  end,
  on_refresh = function (self, event, target, player, data)
    data:cancelTarget(target)
  end,
})
return shengtang